Skip to content

Conversation

@Zsailer
Copy link
Collaborator

@Zsailer Zsailer commented Jul 21, 2025

Fixes #130

The following error was raised "AttributeError: Socket has no such option: ON_RECV" errors during kernel restart operations.

Changes

Kernel Client (kernel_client.py)

  • Enhanced stop_listening() method: Added proper attribute checking with hasattr() to prevent AttributeError when
    _listening_task doesn't exist
  • Added cleanup in finally block: Ensures _listening_task is properly reset to None after cancellation to prevent
    stale references

Kernel Manager (kernel_manager.py)

  • Improved disconnect() method: Added null check for main_client before attempting to stop listening and
    channels, preventing errors when client is already disconnected

Multi-Kernel Manager (multi_kernel_manager.py)

  • Added restart_kernel() method: Implemented proper kernel restart that bypasses problematic activity watching
    and buffering, calling the pinned superclass method directly to avoid ZMQ socket issues

Problem Solved

The original error occurred because jupyter_server's _async_restart_kernel method was trying to use outdated ZMQ
socket options. This fix works around the issue by:

  1. Properly handling missing attributes during client cleanup
  2. Adding safety checks for null clients during disconnection
  3. Implementing a clean restart path that avoids the problematic ZMQ code

@Zsailer Zsailer added the bug Something isn't working label Jul 21, 2025
@ellisonbg ellisonbg merged commit b666a27 into jupyter-ai-contrib:main Jul 22, 2025
3 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel restarts are broken

2 participants